package com.turing.manage.baojian;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.Map;

import com.turing.dao.Dao;
import com.turing.dao.DaoImpl;

public class BaoJianService {
	
	Dao dao = new DaoImpl();
	
	public List<Map<String, Object>> queryCourseAll() throws ClassNotFoundException, SQLException {
		return dao.executeQueryForList("select * from baojian");
	}

	
	/**
	 *  desc 添加方法的 执行
	 * @param course_name
	 * @param course_time
	 * @throws ClassNotFoundException
	 * @throws FileNotFoundException
	 * @throws SQLException
	 * @throws IOException
	 */
	public void addCourse(String course_name, String course_time) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException {
		String sql="insert into baojian values('"+(int)(Math.random()*100)+"',?,?)";
		
		int [] types=new int [2];
		types[0]=Types.VARCHAR;
		types[1]=Types.VARCHAR;
		
		Object [] values=new Object[2];
		values[0]=course_name;
		values [1] =course_time;
		
		dao.executeUpdate(sql, types, values);
		
		
	}


	/**
	 *  desc 
	 * @param course_id
	 * @return
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	public Map<String, Object> queryBaojianById(String room_id) throws ClassNotFoundException, SQLException {

		
		return dao.executeQueryForMap("select * from baojian where room_id='"+room_id+"'");
	}


	public void updateBaojian(String room_id, String room_name, String room_size) throws ClassNotFoundException, SQLException {
				
		dao.executeUpdate("update baojian set room_name='"+room_name+"',room_size='"+room_size+"' where room_id='"+room_id+"'");

		
	}


	public void deleteBaojianByIds(String[] delids) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException {
		 for(int i =0;i<delids.length;i++)
	     {
			    //2.根据课程id删除       			其他表中的信息
			String sql1 = "delete from baojian where room_id=?";
			
		    dao.executeUpdate(sql1, new int []{Types.VARCHAR}, new Object[]{delids[i]});
		     }
		
		
	}

	
}
